﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="AutoSell.aspx.cs" Inherits="WebTraderLite.Pages.AutoSell" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

<asp:SqlDataSource ID="userStocksSDS" runat="server" 
        ConnectionString="<%$ ConnectionStrings:webtraderliteConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:webtraderliteConnectionString.ProviderName %>" 
        SelectCommand="SELECT stockSymbol FROM userstock WHERE (loginName=@userName)"></asp:SqlDataSource>
   
    <asp:ObjectDataSource ID="autosellStockODS" runat="server" 
        SelectMethod="getStockInfo" TypeName="WebTraderLiteCL.stockDataQuery">
        <SelectParameters>
            <asp:ControlParameter ControlID="lstUserStocks" Name="symbol" PropertyName="SelectedValue" 
                Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource> 

   <asp:MultiView ID="MultiViewautosellStock" runat="server" ActiveViewIndex="0">

     <asp:View ID="viewautosellStock" runat="server">
         
            <div>
                <table>
                    <tr>
                        <td>Select stock to autosell:</td>
                        <td><asp:DropDownList ID="lstUserStocks" runat="server" 
                                DataSourceID="userStocksSDS" DataTextField="stockSymbol" 
                                AppendDataBoundItems="true" AutoPostBack="True" 
                                onselectedindexchanged="lstUserStocks_SelectedIndexChanged">
                            <asp:ListItem Text="Select a stock to sell" Value=""></asp:ListItem>
                        </asp:DropDownList></td>
                    </tr>
                </table>
        
            </div>
    
            <span class="failureNotification">
                <asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
            </span>
            <asp:ValidationSummary ID="autosellStockValidationSummary" runat="server" CssClass="failureNotification" 
                    ValidationGroup="autosellStockValidationGroup"/>
    
            <br />
            <div>
                <asp:FormView ID="fvautosellStock" runat="server" DataSourceID="autosellStockODS">
                    <ItemTemplate>
                        <table frame="void">
                            <tr>
                                <td style="font-weight:bold">Stock:</td>
                                <td> <%# Eval("Symbol") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Company:</td>
                                <td> <%# Eval("CompanyName") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Current Price:</td>
                                <td> <%# Eval("Price", "{0:C}") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Auto-Sell Price:</td>
                                <td><asp:TextBox ID="tbAutoSellPrice" runat="server"></asp:TextBox></td>
                                <asp:RequiredFieldValidator ID="RequiredAutoSalePrice" runat="server" ControlToValidate="tbAutoSellPrice"
                                    CssClass="failureNotification" ErrorMessage="Enter price at which to you would like your stock to be automatically sold." 
                                    ValidationGroup="autosellStockValidationGroup" Display="None"></asp:RequiredFieldValidator>

                                <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToValidate="tbAutoSellPrice"
                                    ValidationGroup="autosellStockValidationGroup" Operator="GreaterThan" ValueToCompare="0"
                                    Type="Integer" ErrorMessage="Number of Shares to autosell must be &gt; 0" CssClass="failureNotification" Display="None"></asp:CompareValidator>

                            </tr>

                            <tr>
                                <td style="font-weight:bold; width:90px">Number of Shares to AutoSell:</td>
                                <td><asp:TextBox ID="tbNumShares" runat="server"></asp:TextBox></td>
                                <asp:RequiredFieldValidator ID="numSharesRequired" runat="server" ControlToValidate="tbNumShares"
                                    CssClass="failureNotification" ErrorMessage="Enter number of shares to autosell." 
                                    ValidationGroup="autosellStockValidationGroup" Display="None"></asp:RequiredFieldValidator>

                                <asp:CompareValidator ID="numSharesGreaterThanZero" runat="server" ControlToValidate="tbNumShares"
                                    ValidationGroup="autosellStockValidationGroup" Operator="GreaterThan" ValueToCompare="0"
                                    Type="Integer" ErrorMessage="Number of Shares to autosell must be &gt; 0" CssClass="failureNotification" Display="None"></asp:CompareValidator>
                                
                                <td style="font-style:italic">of available <asp:Label ID="lblSharesOwned" runat="server" Font-Bold="true"></asp:Label></td>

                            </tr>
                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnautosellStock" runat="server" Width="60%" Text="Schedule AutoSale" OnClick="showConfirmautosell" CausesValidation="true" ValidationGroup="autosellStockValidationGroup"/>
                                </td>
                            </tr>
                        </table>
                    </ItemTemplate>            
                </asp:FormView>
                
            </div>

       </asp:View>
       
       <asp:View ID="viewConfirmautosell" runat="server">
       <div style="margin-left:15px">
        <h2>Transaction Summary</h2>
       </div>
       
       <br />

        <div style="margin-left:auto; margin-right:auto">
                <asp:FormView ID="fvConfirmautosell" runat="server" DataSourceID="autosellStockODS"
                    Width="365px">
                    <ItemTemplate>
                        <table frame="void">
                            <tr>
                                <td style="font-weight:bold">Stock:</td>
                                <td align="right"> <asp:Label ID="lblStockSym" runat="server" Text='<%# Eval("Symbol") %>'></asp:Label></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Company:</td>
                                <td align="right"> <%# Eval("CompanyName") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Current Price:</td>
                                <td align="right"> <%# Eval("Price", "{0:C}") %></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold"> Purchase Price:</td>
                                <td align="right"> <asp:Label ID="lblPurchasePrice" runat="server"></asp:Label></td>
                            </tr>
                            <tr>
                                <td style="font-weight:bold">Auto Sell Price:</td>
                                <td align="right"><asp:Label ID="lblAutoSellPrice" runat="server"></asp:Label></td>
                            </tr>

                            <tr>
                                <td style="font-weight:bold">Number of Shares:</td>
                                <td align="right"><asp:Label ID="lblNumShares" runat="server"></asp:Label></td>                            
                            </tr>
                            
                            <tr>
                                <td style="font-weight:bold">Potential Profit/Loss:</td>
                                <td align="right"><asp:Label ID="lblProfitLoss" runat="server" Font-Bold="true"></asp:Label></td>
                            </tr>

                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnConfrimSale" runat="server" Width="65%" Text="Confirm Sale" OnClick="processSale" />
                                </td>                               
                            </tr>
                            
                            <tr>
                                <td colspan="2" style="text-align:right"> 
                                <asp:Button ID="btnCancelautosell" runat="server" Width="65%" Text="Cancel" OnClick="cancelautosell"/>
                                </td>                               
                            </tr>
                        </table>
                    </ItemTemplate>            
                </asp:FormView>
            </div>
       
       </asp:View>    
</asp:MultiView>


</asp:Content>
